/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 *
 * $Id: HeightMapDisplay.hpp,v 1.6 2008-01-16 10:09:15 jari Exp $
 *
 */
#ifndef HEIGHT_MAP_DISPLAY_H_
#define HEIGHT_MAP_DISPLAY_H_

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <vector>
#include <list>
#include "TGroundModelMap.h"

#define X_AX                    0
#define Y_AX                    1
#define Z_AX                    2

#define MIN(a,b) ((a>b)?b:a)
#define MAX(a,b) ((a<b)?b:a)


using namespace std;

/**
 * Struct representing a single point in 3D space
 */

typedef struct __gspot // HarHarHar ;)
{
  float x;
  float y;
  float z;
} TGraphPoint, TGraphVector;

TGraphVector operator - (const TGraphVector &a, const TGraphVector &b);
TGraphVector operator + (const TGraphVector &a, const TGraphVector &b);

bool operator == (const TGraphVector &a, const TGraphVector &b);

typedef vector<TGraphPoint> TGraphPointVector;
typedef vector<TGraphPoint>::iterator TGraphPointVectorIterator;

/**
 * Structure representing a single Triangle in 3D space.
 */
typedef struct __gtriangle
{
  TGraphPoint a;
  TGraphPoint b;
  TGraphPoint c;
} TGraphTriangle;
  
typedef vector<TGraphTriangle> TGraphTriangleVector;
typedef vector<TGraphTriangle>::iterator TGraphTriangleVectorIterator;

typedef struct __gcolor
{
  float red;
  float green;
  float blue;
  float other;
} TGraphColor;

typedef vector<TGraphColor> TGraphColorVector;
typedef vector<TGraphColor>::iterator TGraphColorVectorIterator;

/**
* Call this from your display func
*/
void hm_draw(float x, float y, float z);

TGraphVector hm_crossProductVector(const TGraphVector &v1, 
                                             const TGraphVector &v2);

TGraphVector hm_normalizeVector(const TGraphVector &v);

TGraphVector hm_calculateFaceNormal(const TGraphTriangle &t);

TGraphVector hm_calculateVertexNormal(const TGraphPoint &vertex, 
                                                const TGraphPointVector &near);
float hm_calculatePointDistance( float *p1, float *p2 );

TGraphVector hm_constructNormalForHeightMapPoint(float **heightMap,int x, int z,
                                                             float xR, float yR,
                                                             float zR);

int hm_generateHeightMapDisplayList(TGroundModelMap *map);


#endif //HEIGHT_MAP_DISPLAY_H_
